package com.cloudz.iptv.bing;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.cloudz.iptv.R;
import com.cloudz.iptv.SplashActivity;
import com.cloudz.iptv.activity.BaseActivity;
import com.cloudz.iptv.api.ApiConstants;
import com.cloudz.iptv.api.v1.BingServiceApi;
import com.cloudz.iptv.utils.AppMacUtils;
import com.cloudz.iptv.utils.RetrofitUtils;
import com.cloudz.iptv.utils.SimplePreference;
import com.owen.widget.RoundFrameLayout;

import org.apache.commons.lang3.StringUtils;

import butterknife.BindView;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BingAddrActivity extends BaseActivity
{
    @BindView(R.id.bing_btn_connect)
    RoundFrameLayout bing_btn_connect;

    @BindView(R.id.server_url)
    EditText server_url;

    @Override
    public int getLayoutId()
    {
        return R.layout.activity_bing_addr;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        String content = SimplePreference.getServerUrl(BingAddrActivity.this);

        if (StringUtils.isNoneBlank(content))
        {
            server_url.setText(content);
        } else
        {
            content = server_url.getText().toString();
        }

        server_url.setSelection(content.length());

        // 设置按钮监听
        bing_btn_connect.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                final String server = server_url.getText().toString();

                if (StringUtils.isBlank(server))
                {
                    showToast("服务器地址不能为空");
                } else
                {
                    // 设置请求地址
                    SimplePreference.putString(BingAddrActivity.this, ApiConstants.BASE_URL, server);

                    Intent intent = new Intent(BingAddrActivity.this, BingConnectActivity.class);
                    startActivity(intent);
                }
//
            }
        });
    }

}
